package vd

import (
	"testing"
	"bytes"
	"strings"
	"compress/gzip"
)


var sampleText = `VerboseData01
[] | :vd:Shape:
-
	-
		Point
			Name "O"
			Position
				X 0
				Y 0
	-
		PointGroup
			Points
				-
					Name "A"
					Position
						X 1
						Y 1
				-
					Name "B"
					Position
						X -5
						Y 7
				-
					Name "C"
					Position
						X 10
						Y 15
	-
		Circle
			Center
				X 0
				Y 0
			Radius 0
			Border none
	-
		Circle
			Center
				X 0.5
				Y 1.5
			Radius 10
			Border none
	-
		Circle
			Center
				X 2.5
				Y 3.5
			Radius 6
			Border
				- 2
	-
		Empty
`
func testDeserializeBigGzipped(n uint) (Object, *Type, error) {
	var ts = sampleTransformer
	var bin, _, err1 = testSerializeBigGzipped(n)
	if err1 != nil { return nil, nil, err1 }
	var reader, err2 = gzip.NewReader(bytes.NewReader(bin))
	if err2 != nil { return nil, nil, err2 }
	return Deserialize(reader, nil, ts.Deserializer)
}

func TestDeserialize(t *testing.T) {
	t.Log("deserialize a sample text")
	var ts = sampleTransformer
	var reader = strings.NewReader(sampleText)
	var obj, typ, err = Deserialize(reader, nil, ts.Deserializer)
	if err != nil { t.Fatal(err) }
	t.Logf("%s\n%+v", typ, obj)
}

func TestDeserializeBigGzipped1e3(t *testing.T) {
	var _, _, err = testDeserializeBigGzipped(1000)
	if err != nil { t.Fatal(err) }
}

func TestDeserializeBigGzipped1e4(t *testing.T) {
	var _, _, err = testDeserializeBigGzipped(10000)
	if err != nil { t.Fatal(err) }
}

func TestDeserializeBigGzipped1e5(t *testing.T) {
	var _, _, err = testDeserializeBigGzipped(100000)
	if err != nil { t.Fatal(err) }
}


